package factory.simplefactory.order;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import factory.tradition.storepizza.Pizza;

/**
 * 简单工厂模式
 * @author DFD
 * @date 2023年11月13日
 */
public class OrderPizza {
	// 构造器
	public OrderPizza(SimpleFactory simpleFactory) {
		setFactory(simpleFactory);
	}

	private void setFactory(SimpleFactory simpleFactory) {
		Pizza pizza;
		do {
			String type = getType();
			pizza = simpleFactory.createPizza(type);

			// 输出pizza
			if (pizza != null) { // 订购成功
				pizza.prepare();
				pizza.bake();
				pizza.cut();
				pizza.box();
			} else {
				System.out.println(" 订购披萨失败 ");
				break;
			}
		} while (true);
	}

	/**
	 * 用户输入的pizza类型
	 * @return
	 */
	private String getType() {
		try {
			BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("input pizza 种类:");
			String str = strin.readLine();
			return str;
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}
}
